Use .is_empty() where appropriate
authormcarton <cartonmartin+git@gmail.com>
Fri, 15 Jan 2016 14:51:28 +0000 (15:51 +0100)
committermcarton <cartonmartin+git@gmail.com>
Sat, 16 Jan 2016 11:42:56 +0000 (12:42 +0100)
Fix all of Clippy’s len_zero warnings.

18 files changed:
src/cargo/core/registry.rs
src/cargo/core/resolver/mod.rs
src/cargo/ops/cargo_clean.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_doc.rs
src/cargo/ops/cargo_generate_lockfile.rs
src/cargo/ops/cargo_install.rs
src/cargo/ops/cargo_rustc/context.rs
src/cargo/ops/cargo_rustc/fingerprint.rs
src/cargo/ops/cargo_rustc/job_queue.rs
src/cargo/ops/cargo_test.rs
src/cargo/sources/path.rs
src/cargo/sources/registry.rs
src/cargo/util/dependency_queue.rs
src/cargo/util/errors.rs
src/cargo/util/toml.rs
tests/support/mod.rs
tests/support/registry.rs

index d9daa1c9436b9c8cdbe78fecb7c834ec691fe74c..60a82d300882ef01232ae96482ae7d9c9d892750 100644 (file)
@@ -295,7 +295,7 @@ impl<'cfg> Registry for PackageRegistry<'cfg> {
     fn query(&mut self, dep: &Dependency) -> CargoResult<Vec<Summary>> {
         let overrides = try!(self.query_overrides(dep));
 
-        let ret = if overrides.len() == 0 {
+        let ret = if overrides.is_empty() {
             // Ensure the requested source_id is loaded
             try!(self.ensure_loaded(dep.source_id(), Kind::Normal));
             let mut ret = Vec::new();
index 5e2dc39a0c72536569d2061dbd254f9f0638f420..ceb4b4afd67e907bbedcd4720560eaa69e61c626 100644 (file)
@@ -453,7 +453,7 @@ fn activation_error(cx: &Context,
     candidates.sort_by(|a, b| {
         b.version().cmp(a.version())
     });
-    if candidates.len() > 0 {
+    if !candidates.is_empty() {
         msg.push_str("\nversions found: ");
         for (i, c) in candidates.iter().take(3).enumerate() {
             if i != 0 { msg.push_str(", "); }
@@ -469,7 +469,7 @@ fn activation_error(cx: &Context,
     // update`. In this case try to print a helpful error!
     if dep.source_id().is_path() &&
        dep.version_req().to_string().starts_with("=") &&
-       candidates.len() > 0 {
+       !candidates.is_empty() {
         msg.push_str("\nconsider running `cargo update` to update \
                       a path dependency's locked version");
 
@@ -607,7 +607,7 @@ impl Context {
                     (!use_default || prev.contains("default") ||
                      !has_default_feature)
             }
-            None => features.len() == 0 && (!use_default || !has_default_feature)
+            None => features.is_empty() && (!use_default || !has_default_feature)
         }
     }
 
@@ -686,10 +686,10 @@ impl Context {
         // they should have all been weeded out by the above iteration. Any
         // remaining features are bugs in that the package does not actually
         // have those features.
-        if feature_deps.len() > 0 {
+        if !feature_deps.is_empty() {
             let unknown = feature_deps.keys().map(|s| &s[..])
                                       .collect::<Vec<&str>>();
-            if unknown.len() > 0 {
+            if !unknown.is_empty() {
                 let features = unknown.connect(", ");
                 bail!("Package `{}` does not have these features: `{}`",
                       parent.package_id(), features)
@@ -697,7 +697,7 @@ impl Context {
         }
 
         // Record what list of features is active for this package.
-        if used_features.len() > 0 {
+        if !used_features.is_empty() {
             let pkgid = parent.package_id();
             self.resolve.features.entry(pkgid.clone())
                 .or_insert(HashSet::new())
index 7b3676b5427f9cc533fc3c073b09f94997a03a39..b14b4025de783fc2cedec5fc626141401573121e 100644 (file)
@@ -22,7 +22,7 @@ pub fn clean(manifest_path: &Path, opts: &CleanOptions) -> CargoResult<()> {
 
     // If we have a spec, then we need to delete some packages, otherwise, just
     // remove the whole target directory and be done with it!
-    if opts.spec.len() == 0 {
+    if opts.spec.is_empty() {
         return rm_rf(&target_dir);
     }
 
index 43995c0d0531f9b37bbfc1cb4e7dee4b12efef6e..ce301935c277103f85afc2e3c6b82f1c8a452f10 100644 (file)
@@ -176,7 +176,7 @@ pub fn compile_pkg<'a>(root_package: &Package,
         vec![root_package.package_id()]
     };
 
-    if spec.len() > 0 && invalid_spec.len() > 0 {
+    if !spec.is_empty() && !invalid_spec.is_empty() {
         bail!("could not find package matching spec `{}`",
               invalid_spec.connect(", "))
     }
index 8d843f31c93c7049418d6ed795ff34faeeef6950..a6c38c295d47d99ee0709e31430e124478ccf430 100644 (file)
@@ -18,7 +18,7 @@ pub fn doc(manifest_path: &Path,
 
     let mut lib_names = HashSet::new();
     let mut bin_names = HashSet::new();
-    if options.compile_opts.spec.len() == 0 {
+    if options.compile_opts.spec.is_empty() {
         for target in package.targets().iter().filter(|t| t.documented()) {
             if target.is_lib() {
                 assert!(lib_names.insert(target.crate_name()));
index f120a395f0649823ca8f35ae97d4f7bef0e1fe4e..fc2cdf4301f7a25abd19b61c0d9997887eeb243c 100644 (file)
@@ -43,7 +43,7 @@ pub fn update_lockfile(manifest_path: &Path,
     let mut registry = PackageRegistry::new(opts.config);
     let mut to_avoid = HashSet::new();
 
-    if opts.to_update.len() == 0 {
+    if opts.to_update.is_empty() {
         to_avoid.extend(previous_resolve.iter());
     } else {
         let mut sources = Vec::new();
index dfe9ea3614134c2b911ab18b71e0fa1bb71e7639..0554fcd7ba42dc670b39e932d053be3b7a9ebd2c 100644 (file)
@@ -312,7 +312,7 @@ pub fn uninstall(root: Option<&str>,
             }
         }
 
-        if bins.len() == 0 {
+        if bins.is_empty() {
             to_remove.extend(installed.get().iter().map(|b| dst.join(b)));
             installed.get_mut().clear();
         } else {
@@ -321,7 +321,7 @@ pub fn uninstall(root: Option<&str>,
                 installed.get_mut().remove(bin);
             }
         }
-        if installed.get().len() == 0 {
+        if installed.get().is_empty() {
             installed.remove();
         }
     }
index 716e04490154818dfa13bfc365bb6b9331cbd25e..34f249b53afccbaf5089af0691bb5068cfac5f8d 100644 (file)
@@ -282,7 +282,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
                 }
             }
         }
-        assert!(ret.len() > 0);
+        assert!(!ret.is_empty());
         Ok(ret)
     }
 
index 66f0fb0ddd349f4907266881e2e789273c675ab3..fcfc6c952176ef6c4b3bccfbd8994cf8f12d6c35 100644 (file)
@@ -398,7 +398,7 @@ pub fn prepare_build_cmd<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
             None => {
                 let &(ref output, ref deps) = &cx.build_explicit_deps[unit];
 
-                let local = if deps.len() == 0 {
+                let local = if deps.is_empty() {
                     let s = try!(pkg_fingerprint(cx, unit.pkg));
                     LocalFingerprint::Precalculated(s)
                 } else {
@@ -440,7 +440,7 @@ pub fn prepare_build_cmd<'a, 'cfg>(cx: &mut Context<'a, 'cfg>, unit: &Unit<'a>)
     let write_fingerprint = Work::new(move |_| {
         if let Some(output_path) = output_path {
             let outputs = state.outputs.lock().unwrap();
-            if outputs[&key].rerun_if_changed.len() > 0 {
+            if !outputs[&key].rerun_if_changed.is_empty() {
                 let slot = MtimeSlot(Mutex::new(None));
                 fingerprint.local = LocalFingerprint::MtimeBased(slot,
                                                                  output_path);
index 6dea0a60df7da4f1e1c85d299b56bf69c638b04f..30d6394c28ff8cedb93b4bfdf75c056380c5a2e7 100644 (file)
@@ -104,7 +104,7 @@ impl<'a> JobQueue<'a> {
         // and then immediately return.
         loop {
             while self.active < self.jobs {
-                if queue.len() > 0 {
+                if !queue.is_empty() {
                     let (key, job, fresh) = queue.remove(0);
                     try!(self.run(key, fresh, job, config, scope));
                 } else if let Some((fresh, key, jobs)) = self.queue.dequeue() {
@@ -152,7 +152,7 @@ impl<'a> JobQueue<'a> {
             }
         }
 
-        if self.queue.len() == 0 {
+        if self.queue.is_empty() {
             Ok(())
         } else {
             debug!("queue: {:#?}", self.queue);
index e443748314ac6eca42994b6f11232dd81e1ec1e8..28a19077fcd7c5575bbbf931df5ccfc2b2591c37 100644 (file)
@@ -24,7 +24,7 @@ pub fn run_tests(manifest_path: &Path,
     let mut errors = try!(run_unit_tests(options, test_args, &compilation));
 
     // If we have an error and want to fail fast, return
-    if errors.len() > 0 && !options.no_fail_fast {
+    if !errors.is_empty() && !options.no_fail_fast {
         return Ok(Some(CargoTestError::new(errors)))
     }
 
@@ -38,7 +38,7 @@ pub fn run_tests(manifest_path: &Path,
     }
 
     errors.extend(try!(run_doc_tests(options, test_args, &compilation)));
-    if errors.len() == 0 {
+    if errors.is_empty() {
         Ok(None)
     } else {
         Ok(Some(CargoTestError::new(errors)))
index 1cbead449314472e38baf6ba38f4cb192ac12a39..a6f5aede46db52f66815aa0c781569947a8aae4e 100644 (file)
@@ -106,7 +106,7 @@ impl<'cfg> PathSource<'cfg> {
         let mut filter = |p: &Path| {
             let relative_path = util::without_prefix(p, &root).unwrap();
             include.iter().any(|p| p.matches_path(&relative_path)) || {
-                include.len() == 0 &&
+                include.is_empty() &&
                  !exclude.iter().any(|p| p.matches_path(&relative_path))
             }
         };
index 9bce0dc252aa257c91408c88c01c9b42c4184179..dcfd746505667aaaa51223963c7433ababec8834 100644 (file)
@@ -487,7 +487,7 @@ impl<'cfg> Registry for RegistrySource<'cfg> {
             let mut summaries = try!(self.summaries(dep.name())).iter().map(|s| {
                 s.0.clone()
             }).collect::<Vec<_>>();
-            if try!(summaries.query(dep)).len() == 0 {
+            if try!(summaries.query(dep)).is_empty() {
                 try!(self.do_update());
             }
         }
index 78d48232db4adf0b69c98dec120c233f5bd11ce5..9db5d103c5978aad7bf1f0260ee14165a0ff4cc2 100644 (file)
@@ -99,7 +99,7 @@ impl<K: Dependency, V> DependencyQueue<K, V> {
     /// `None` is returned then no packages are ready to be built.
     pub fn dequeue(&mut self) -> Option<(Freshness, K, V)> {
         let key = match self.dep_map.iter()
-                                    .find(|&(_, &(ref deps, _))| deps.len() == 0)
+                                    .find(|&(_, &(ref deps, _))| deps.is_empty())
                                     .map(|(key, _)| key.clone()) {
             Some(key) => key,
             None => return None
index d374cb50f884ebc2bff94a4af4d1b5887a3abc77..ef2fdeda56651c8cbb5c389e5e8db99ba71771f1 100644 (file)
@@ -142,7 +142,7 @@ pub struct CargoTestError {
 impl CargoTestError {
     #[allow(deprecated)] // connect => join in 1.3
     pub fn new(errors: Vec<ProcessError>) -> Self {
-        if errors.len() == 0 {
+        if errors.is_empty() {
             panic!("Cannot create CargoTestError from empty Vec")
         }
         let desc = errors.iter().map(|error| error.desc.clone())
index e7e910b3c79bf0f243d8245d5beb7bd5e34ce3b3..ff27b024722faf83dc36d724a727e76230fb21c7 100644 (file)
@@ -138,7 +138,7 @@ pub fn to_manifest(contents: &[u8],
         match *toml {
             toml::Value::Table(ref table) => {
                 for (k, v) in table.iter() {
-                    add_unused_keys(m, v, if key.len() == 0 {
+                    add_unused_keys(m, v, if key.is_empty() {
                         k.clone()
                     } else {
                         key.clone() + "." + k
index 91c9a6888d2a0d84f6cddc189bdbca613570b1c5..f57a283a06159ce9cc80621e8b3efafa439c2716 100644 (file)
@@ -370,7 +370,7 @@ impl Execs {
         } else {
             self.diff_lines(a, e, partial)
         };
-        ham::expect(diffs.len() == 0,
+        ham::expect(diffs.is_empty(),
                     format!("differences:\n\
                             {}\n\n\
                             other output:\n\
@@ -416,7 +416,7 @@ fn lines_match(expected: &str, mut actual: &str) -> bool {
             }
         }
     }
-    actual.len() == 0 || expected.ends_with("[..]")
+    actual.is_empty() || expected.ends_with("[..]")
 }
 
 struct ZipAll<I1: Iterator, I2: Iterator> {
index df0d5301a91327632c9f1e775392234e328ce540..2d4910edfbd4e76794c3b692c9bcef0debe137dd 100644 (file)
@@ -157,7 +157,7 @@ impl Package {
         let f = File::create(&dst).unwrap();
         let a = Archive::new(GzEncoder::new(f, Default));
         self.append(&a, "Cargo.toml", &manifest);
-        if self.files.len() == 0 {
+        if self.files.is_empty() {
             self.append(&a, "src/lib.rs", "");
         } else {
             for &(ref name, ref contents) in self.files.iter() {